package com.applancer.fragment;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.View;

import com.applancer.appInterface.ViewPagerEventInteface;
import com.applancer.dataprovider.DataProvider;
import com.applancer.dataprovider.DataType.FeedType;
import com.applancer.delegate.NewFeedDelegate;
import com.applancer.parser.GeneralParser;

public class FeedGeneralFragment extends Fragment {

	protected View contentView;
	protected DataProvider dataProvider;
	protected GeneralParser parser;
	protected String id;
	protected ViewPagerEventInteface viewPagerCallback;

	public static FeedGeneralFragment createInstance(String id, String title) {

		FeedType type = FeedType.valueOfID(id);

		switch (type) {
		case Home:
			return new FeedHomeFragment(id, title, null);
		case Bookmarks:
			return new FeedBookmarksFragment(id, title, null);

		default:
			return new FeedNormalFragment(id, title, null);
		}

	}

	public static FeedGeneralFragment createInstance(String id, String title,
			NewFeedDelegate del) {
		if (id.equals("-10")) {
			return new FeedHomeFragment(id, title, del);
		}

		return new FeedNormalFragment(id, title, del);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {

		super.onActivityCreated(savedInstanceState);

		initial();
		execution();

	}

	@Override
	public void onAttach(Activity activity) {

		try {
			viewPagerCallback = (ViewPagerEventInteface) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(
					"Activity must implement NavigationDrawerCallbacks.");
		}

		super.onAttach(activity);
	}

	protected void initial() {
		dataProvider = new DataProvider(contentView.getContext());

	}

	protected void execution() {
		// do some thing for this fragment
	}
}
